#include <stdio.h>


#define EOS '\0'

/* Return the length of the maximum initial segment
of S which contains only characters in ACCEPT.  */
size_t
strspn (s, accept)
const char *s;
const char *accept;
{
	const char *p;
	const char *a;
	size_t count = 0;
	
	for (p = s; *p != '\0'; ++p)
	{
		for (a = accept; *a != '\0'; ++a)
			if (*p == *a)
				break;
			if (*a == '\0')
				return count;
			else
				++count;
	}
	
	return count;
}

simple_strspn (const char *s, const char *acc)
{
	const char *r, *str = s;
	char c;
	
	while ((c = *s++) != '\0')
	{
		for (r = acc; *r != '\0'; ++r)
			if (*r == c)
				break;
			if (*r == '\0')
				return s - str - 1;
	}
	return s - str - 1;
}

size_t _strspn
(
 const char * s,             /* string to search */
 const char * sep            /* set of characters to look for in <s> */
 )
{
	const char *save;
	const char *p;
	char c1;
	char c2;
	
	for (save = s + 1; (c1 = *s++) != EOS; )
		for (p = sep; (c2 = *p++) != c1; )
		{
			if (c2 == EOS)
				return (s - save);
		}
		
		return (s - save);
}

static void _main( void )
{
	char string[] = "cabbage";
	int  result;
	result = _strspn( string, "abc" );
	printf( "The portion of '%s' containing only a, b, or c "
		"is %d bytes long\n", string, result );
}
